package com.ex.managersystem1024.controller;


import cn.hutool.core.util.StrUtil;
import com.ex.managersystem1024.common.HoneyLogs;
import com.ex.managersystem1024.common.LogType;
import com.ex.managersystem1024.common.Result;
import com.ex.managersystem1024.entity.User;
import com.ex.managersystem1024.entity.dto.LoginDto;
import com.ex.managersystem1024.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(value = "Web Controller", tags = { "登录接口" })
public class WebController {

    @Autowired
    private UserService userService;


    @ApiOperation(value = "登录")
    @HoneyLogs(operation = "用户", type = LogType.LOGIN)
    @PostMapping("/login")
    public Result login(@RequestBody LoginDto loginDto) {
        if (StrUtil.isBlank(loginDto.getUsername()) || StrUtil.isBlank(loginDto.getPassword())) {
            return Result.error("数据输入不合法");
        }
        User user = userService.login(loginDto);
        return Result.success(user);
    }


    


}
